#include "qcolorbutton.h"
#include "qtcolortriangle.h"

QColorButton::QColorButton(QWidget *parent) :
    QPushButton(parent)
{
}

int QColorButton::dialogSize()
{
    return m_size;
}

void QColorButton::setDialogSize(int size)
{
    m_size = size;
}

void QColorButton::changeColor(QColor c)
{
    m_color = c;
    QString style("background-color: rgb(%1, %2, %3); color: rgb(%4, %5, %6);");
    QString text("rgb(%1, %2, %3)");
    setStyleSheet(style.arg(c.red()).arg(c.green()).arg(c.blue())
		  .arg(c.cyan()).arg(c.magenta()).arg(c.yellow()));
    setText(text.arg(c.red()).arg(c.green()).arg(c.blue()));
}

QColor QColorButton::color()
{
    return m_color;
}

void QColorButton::clickedMe()
{
    QtColorTriangle *ct = new QtColorTriangle;
    ct->setColor(m_color);
    connect(ct, SIGNAL(colorChanged(QColor)), this, SLOT(changeColor(QColor)));
    connect(ct, SIGNAL(colorChanged(QColor)), this, SIGNAL(colorChanged(QColor)));
    ct->resize(m_size, m_size);
    ct->show();
}
